/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.pig.pigpen.launch;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;

public class PigMainTab extends AbstractLaunchConfigurationTab {

    Text pigScript;
    Text confPath;

    public void createControl(Composite parent) {
        // TODO Auto-generated method stub

        Composite comp = new Composite(parent, SWT.NONE);
        setControl(comp);
        // PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
        // IJavaDebugHelpContextIds
        // .LAUNCH_CONFIGURATION_DIALOG_APPLET_PARAMETERS_TAB);
        GridLayout topLayout = new GridLayout();
        comp.setLayout(topLayout);
        GridData gd;

        Composite widthHeightNameComp = new Composite(comp, SWT.NONE);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        widthHeightNameComp.setLayoutData(gd);
        GridLayout widthHeightNameLayout = new GridLayout();
        widthHeightNameLayout.marginHeight = 0;
        widthHeightNameLayout.marginWidth = 0;
        widthHeightNameLayout.numColumns = 2;
        widthHeightNameComp.setLayout(widthHeightNameLayout);

        /*
         * Label fWidthLabel= new Label(widthHeightNameComp, SWT.NONE);
         * fWidthLabel.setText("Pig Script");
         */
        new Label(widthHeightNameComp, SWT.NONE).setText("Pig Script : ");

        pigScript = new Text(widthHeightNameComp, SWT.SINGLE | SWT.BORDER);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        pigScript.setLayoutData(gd);

        /*
         * fNameLabel = new Label(widthHeightNameComp, SWT.NONE);
         * fNameLabel.setText
         * (LauncherMessages.appletlauncher_argumenttab_namelabel_text);
         */
        new Label(widthHeightNameComp, SWT.NONE)
                .setText("Configuration Path : ");

        confPath = new Text(widthHeightNameComp, SWT.SINGLE | SWT.BORDER);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        confPath.setLayoutData(gd);

    }

    public String getName() {
        // TODO Auto-generated method stub
        return null;
    }

    public void initializeFrom(ILaunchConfiguration configuration) {
        // TODO Auto-generated method stub
        try {
            pigScript.setText(configuration.getAttribute(
                    IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, ""));
        } catch (CoreException e) {
            // TODO Auto-generated catch block
            pigScript.setText("");
        }

        try {
            confPath.setText(configuration.getAttribute(
                    IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, ""));
        } catch (CoreException e) {
            // TODO Auto-generated catch block
            confPath.setText("");
        }
    }

    public void performApply(ILaunchConfigurationWorkingCopy configuration) {
        // TODO Auto-generated method stub

        configuration.setAttribute(
                IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
                pigScript.getText());
        configuration.setAttribute(
                IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, confPath
                        .getText());
    }

    public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
        // TODO Auto-generated method stub

    }

}
